package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyWmh;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyWmhMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyWmhParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyWmhDto;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyWmhResult;
import  cn.stylefeng.guns.sys.modular.system.service.BtyWmhService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuy
 * @since 2022-02-09
 */
@Service
public class BtyWmhServiceImpl extends ServiceImpl<BtyWmhMapper, BtyWmh> implements BtyWmhService {

    @Override
    public void add(BtyWmhParam param){
        BtyWmh entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtyWmhParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyWmhParam param){
        BtyWmh oldEntity = getOldEntity(param);
        BtyWmh newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyWmhResult findBySpec(BtyWmhParam param){
        return null;
    }

    @Override
    public List<BtyWmhResult> findListBySpec(BtyWmhParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyWmhParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean insertWmh(List<BtyWmhDto> sub) {
        return baseMapper.insertWmh(sub);
    }

    @Override
    public List<BtyWmhResult> wmhList() {
        return baseMapper.wmhList();
    }

    @Override
    public List<BtyWmhResult> sflbList(String dm) {
        return baseMapper.sflbList(dm);
    }


    @Override
    public int updateByDm(BtyWmhParam param) {
        return baseMapper.updateByDm(param);
    }

    @Override
    public int updateErrMsgByDm(BtyWmhParam param) {
        return baseMapper.updateErrMsgByDm(param);
    }

    private Serializable getKey(BtyWmhParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyWmh getOldEntity(BtyWmhParam param) {
        return this.getById(getKey(param));
    }

    private BtyWmh getEntity(BtyWmhParam param) {
        BtyWmh entity = new BtyWmh();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
